home *** CD-ROM | disk | FTP | other *** search
- /*
- Tcl commands for Harvest C
- */
-
- #include <string.h>
-
- #include "CHarvestApp.h"
- #include "CHarvestDoc.h"
- #include "CSourceFile.h"
- #include "CHarvestOptions.h"
- #include "CDataFile.h"
- #include "CList.h"
- #include "CHarvestPane.h"
-
- #include "tcl.h"
-
- #define STREQU(A, B) ( strcmp ( (A) , (B) ) == 0 )
-
- extern CHarvestDoc *gProject;
- extern CHarvestApp *gApplication;
-
- static int
- Tcl_newProject(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int myerr;
- short vrefnum;
- long dirid;
- char *ptr1, savech, *namep;
- char pascal_name[64];
- CHarvestDoc *newDocument;
-
- if (gProject) {
- Tcl_SetResult(interp, "there is a project already open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc == 1) {
- gApplication->CreateProject();
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- return TCL_OK;
- }
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- namep = argv[1];
- dirid = current_dirid();
- vrefnum = current_vrefnum();
- ptr1 = strrchr(namep, ':');
-
- if (ptr1 != NULL) {
- savech = *(ptr1+1);
- *(ptr1+1) = '\0';
- dirid = compute_path_dirid(namep);
- *(ptr1+1) = savech;
- strcpy(pascal_name, ptr1 + 1);
- vrefnum = compute_path_vrefnum(namep);
- }
- else
- strcpy(pascal_name, namep);
-
- c2pstr(pascal_name);
- newDocument = new(CHarvestDoc);
- newDocument->IHarvestDoc(gApplication,false);
- newDocument->FSNewFile(pascal_name,vrefnum,dirid);
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_openProject(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int myerr;
- short vrefnum;
- long dirid;
- char *ptr1, savech, *namep;
- char pascal_name[64];
- CHarvestDoc *newDocument;
- if (gProject) {
- Tcl_SetResult(interp, "there is a project already open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc == 1) {
- DoOpenProject();
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- return TCL_OK;
- }
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- namep = argv[1];
- dirid = current_dirid();
- vrefnum = current_vrefnum();
- ptr1 = strrchr(namep, ':');
-
- if (ptr1 != NULL) {
- savech = *(ptr1+1);
- *(ptr1+1) = '\0';
- dirid = compute_path_dirid(namep);
- *(ptr1+1) = savech;
- strcpy(pascal_name, ptr1 + 1);
- vrefnum = compute_path_vrefnum(namep);
- }
- else
- strcpy(pascal_name, namep);
-
- c2pstr(pascal_name);
- newDocument = new(CHarvestDoc);
- newDocument->IHarvestDoc(gApplication,false);
- newDocument->FSOpenFile(pascal_name,vrefnum,dirid);
- if (gProject) {
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- }
- else {
- Tcl_SetResult(interp, "openProject failed", TCL_STATIC);
- }
- return TCL_OK;
- }
- }
-
- static int
- Tcl_closeProject(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- gProject->Close(false);
- Tcl_SetResult(interp, "1", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_setOption(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int value;
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 3) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- value = atoi(argv[2]);
- if (STREQU(argv[1],"trigraphs")) {
- gProject->itsOptions->trigraphs = value;
- }
- if (STREQU(argv[1],"bigGlobals")) {
- gProject->itsOptions->bigGlobals = value;
- }
- if (STREQU(argv[1],"mc68020")) {
- gProject->itsOptions->useMC68020 = value;
- }
- if (STREQU(argv[1],"mc68881")) {
- gProject->itsOptions->useMC68881 = value;
- }
- if (STREQU(argv[1],"signedChars")) {
- gProject->itsOptions->signedChars = value;
- }
- if (STREQU(argv[1],"macsbugSyms")) {
- gProject->itsOptions->MacsBugSymbols = value;
- }
- Tcl_SetResult(interp, argv[2], TCL_VOLATILE);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_setWarnings(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int value;
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 3) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- value = atoi(argv[2]);
- if (STREQU(argv[1],"all")) {
- if (value) {
- gProject->itsOptions->allWarnings = 1;
- gProject->itsOptions->noWarnings = 0;
- }
- else {
- gProject->itsOptions->allWarnings = 0;
- gProject->itsOptions->noWarnings = 1;
- }
- }
- /* TODO Search for the warning in the array */
- Tcl_SetResult(interp, argv[2], TCL_VOLATILE);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_setSig(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- gProject->itsSignature = MakeOSType(argv[1]);
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_setPartition(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- gProject->itsPartition = atoi(argv[1])*1024;
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_setSIZEFlags(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- gProject->itsSizeFlags = atoi(argv[1]);
- Tcl_SetResult(interp, argv[1], TCL_VOLATILE);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_bringUpToDate(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- if (gProject->BringUpToDate()) {
- Tcl_SetResult(interp, "1", TCL_STATIC);
- }
- else {
- Tcl_SetResult(interp, "0", TCL_STATIC);
- }
- return TCL_OK;
- }
- }
-
- static int
- Tcl_buildApplication(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int myerr;
- short vrefnum;
- long dirid;
- char *ptr1, savech, *namep;
- char pascal_name[64];
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc == 1) {
- gProject->Link();
- Tcl_SetResult(interp, "1", TCL_STATIC);
- return TCL_OK;
- }
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- namep = argv[1];
- dirid = current_dirid();
- vrefnum = current_vrefnum();
- ptr1 = strrchr(namep, ':');
-
- if (ptr1 != NULL) {
- savech = *(ptr1+1);
- *(ptr1+1) = '\0';
- dirid = compute_path_dirid(namep);
- *(ptr1+1) = savech;
- strcpy(pascal_name, ptr1 + 1);
- vrefnum = compute_path_vrefnum(namep);
- }
- else
- strcpy(pascal_name, namep);
-
- c2pstr(pascal_name);
-
- CopyPString(pascal_name,gProject->StdAppName);
- gProject->StdAppVol = vrefnum;
- gProject->StdAppDir = dirid;
-
- if (gProject->DoLink()) {
- Tcl_SetResult(interp, "1", TCL_STATIC);
- }
- else {
- Tcl_SetResult(interp, "0", TCL_STATIC);
- }
- return TCL_OK;
- }
- }
-
- static int
- Tcl_makeClean(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- gProject->Clean();
- Tcl_SetResult(interp, "cleaned", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_runApplication(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- if (argc != 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- gProject->RunApp();
- Tcl_SetResult(interp, "1", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_addFiles(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int myerr;
- short vrefnum;
- long dirid;
- char *ptr1, savech, *namep;
- char pascal_name[64];
- int i;
- int len;
- if (argc <= 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- for (i=1; i<=(argc-1); i++) {
- namep = argv[1];
- dirid = current_dirid();
- vrefnum = current_vrefnum();
- ptr1 = strrchr(namep, ':');
-
- if (ptr1 != NULL) {
- savech = *(ptr1+1);
- *(ptr1+1) = '\0';
- dirid = compute_path_dirid(namep);
- *(ptr1+1) = savech;
- strcpy(pascal_name, ptr1 + 1);
- vrefnum = compute_path_vrefnum(namep);
- }
- else
- strcpy(pascal_name, namep);
-
- c2pstr(pascal_name);
- len = pascal_name[0];
- if (pascal_name[len-1] == '.') {
- if (pascal_name[len] == 'o') {
- /* TODO Should make sure file is 'OBJ ' */
- gProject->AddLibraryFileHFS((unsigned char *) pascal_name,vrefnum,dirid);
- }
- else {
- /* TODO Should make sure file is 'TEXT' */
- gProject->AddSourceFileHFS((unsigned char *) pascal_name,vrefnum,dirid);
- }
- }
- else {
- /* TODO Should make sure file is 'rsrc' */
- gProject->AddResourceFileHFS((unsigned char *) pascal_name,vrefnum,dirid);
- }
- }
-
- Tcl_SetResult(interp, "1", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_removeFiles(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int myerr;
- short vrefnum;
- long dirid;
- char *ptr1, savech, *namep;
- char pascal_name[64];
- int i;
- int ndx;
- if (argc <= 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- for (i=1; i<=(argc-1); i++) {
- namep = argv[1];
- dirid = current_dirid();
- vrefnum = current_vrefnum();
- ptr1 = strrchr(namep, ':');
-
- if (ptr1 != NULL) {
- savech = *(ptr1+1);
- *(ptr1+1) = '\0';
- dirid = compute_path_dirid(namep);
- *(ptr1+1) = savech;
- strcpy(pascal_name, ptr1 + 1);
- vrefnum = compute_path_vrefnum(namep);
- }
- else
- strcpy(pascal_name, namep);
-
- c2pstr(pascal_name);
-
- ndx = gProject->FindFile(pascal_name,vrefnum,dirid);
- if (ndx) {
- gProject->itsSourceFiles->Remove(gProject->itsSourceFiles->NthItem(ndx));
- gProject->itsTable->DeleteRow(1,ndx);
- gProject->itsTable->DeselectAll(true);
- }
- }
- Tcl_SetResult(interp, "1", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_compile(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int myerr;
- short vrefnum;
- long dirid;
- char *ptr1, savech, *namep;
- char pascal_name[64];
- int ndx;
- CSourceFile *srcFile;
-
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- namep = argv[1];
- dirid = current_dirid();
- vrefnum = current_vrefnum();
- ptr1 = strrchr(namep, ':');
-
- if (ptr1 != NULL) {
- savech = *(ptr1+1);
- *(ptr1+1) = '\0';
- dirid = compute_path_dirid(namep);
- *(ptr1+1) = savech;
- strcpy(pascal_name, ptr1 + 1);
- vrefnum = compute_path_vrefnum(namep);
- }
- else
- strcpy(pascal_name, namep);
-
- c2pstr(pascal_name);
-
- ndx = gProject->FindFile(pascal_name,vrefnum,dirid);
- if (ndx) {
- srcFile = (CSourceFile *) gProject->itsSourceFiles->NthItem(ndx);
- if (srcFile->itsKind == H_SourceFile) {
- srcFile->Compile();
- }
- }
-
- Tcl_SetResult(interp, "0", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_openFile(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- if (argc != 2) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
- /* TODO send an AE to open the given file - return success */
- Tcl_SetResult(interp, "openFile currently not implemented", TCL_STATIC);
- return TCL_OK;
- }
- }
-
- static int
- Tcl_listProject(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- int CountSourceFiles;
- int i;
- CSourceFile *aFile;
- CDataFile *theFile;
- char name[256];
-
- if (argc != 1) {
- Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
- return TCL_ERROR;
- }
- else {
- if (!gProject) {
- Tcl_SetResult(interp, "no project open", TCL_STATIC);
- return TCL_ERROR;
- }
-
- Tcl_ResetResult(interp);
-
- CountSourceFiles = gProject->itsSourceFiles->GetNumItems();
- for (i=1;i<=CountSourceFiles;i++) {
- aFile = (CSourceFile *) gProject->itsSourceFiles->NthItem(i);
- theFile = aFile->theFile;
- CopyPString(theFile->name,name);
- p2cstr(name);
- Tcl_AppendElement(interp,name,0);
- }
- return TCL_OK;
- }
- }
-
- void
- InitHarvestTcl(Tcl_Interp *interp)
- {
- int result;
-
- Tcl_CreateCommand(interp, "newProject", Tcl_newProject, NULL, NULL);
- Tcl_CreateCommand(interp, "openProject", Tcl_openProject, NULL, NULL);
- Tcl_CreateCommand(interp, "closeProject", Tcl_closeProject, NULL, NULL);
- Tcl_CreateCommand(interp, "setOption", Tcl_setOption, NULL, NULL);
- Tcl_CreateCommand(interp, "setWarnings", Tcl_setWarnings, NULL, NULL);
- Tcl_CreateCommand(interp, "setSig", Tcl_setSig, NULL, NULL);
- Tcl_CreateCommand(interp, "setPartition", Tcl_setPartition, NULL, NULL);
- Tcl_CreateCommand(interp, "setSIZEFlags", Tcl_setSIZEFlags, NULL, NULL);
- Tcl_CreateCommand(interp, "bringUpToDate", Tcl_bringUpToDate, NULL, NULL);
- Tcl_CreateCommand(interp, "buildApplication", Tcl_buildApplication, NULL, NULL);
- Tcl_CreateCommand(interp, "makeClean", Tcl_makeClean, NULL, NULL);
- Tcl_CreateCommand(interp, "runApplication", Tcl_runApplication, NULL, NULL);
- Tcl_CreateCommand(interp, "addFiles", Tcl_addFiles, NULL, NULL);
- Tcl_CreateCommand(interp, "removeFiles", Tcl_removeFiles, NULL, NULL);
- Tcl_CreateCommand(interp, "compile", Tcl_compile, NULL, NULL);
- Tcl_CreateCommand(interp, "listProject", Tcl_listProject, NULL, NULL);
- Tcl_CreateCommand(interp, "openFile", Tcl_openFile, NULL, NULL);
-
- }
-
-
-